
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: AtomicFieldModel.java 295 2010-01-13 21:03:17Z archie.cobbs $
 */

package org.dellroad.sidekar.schema.model;

import org.dellroad.sidekar.FieldType;

/**
 * Superclass for atomic schema fields.
 */
public abstract class AtomicFieldModel extends SimpleFieldModel {

    // Normal constructor
    AtomicFieldModel(String typeName) {
        super(typeName);
    }

    // Copy constructor
    AtomicFieldModel(AtomicFieldModel original) {
        super(original);
    }

    /**
     * Get the {@link AtomicFieldModel} type corresponding to the given Java class.
     *
     * @return the corresponding {@link AtomicFieldModel} class
     * @throws IllegalArgumentException if no such field model type exists
     */
    public static Class<? extends AtomicFieldModel> getModelType(Class<?> javaType) {
        try {
            return FieldType.forJavaType(javaType).getFieldModelType().asSubclass(AtomicFieldModel.class);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("no known atomic field model type for " + javaType);
        }
    }
}

